package kam.fire;



import java.util.ArrayList;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonRootName;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;

@JsonRootName(value = "message")
public class Message implements Comparable<Message> {
	
	DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
	
	private String type;
	private String body;
	@JsonProperty("created_at")
	private String dateCreated;
	@JsonProperty("id")
	private int Id;
	private int Index;
	private int roomIndex;
	private int userIndex;
	@JsonProperty("room_id")
	private int roomId;
	@JsonProperty("user_id")
	private int userId;
	private boolean starred;

	public ArrayList<Message> messages;

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	public int getRoomId() {
		return roomId;
	}

	public void setRoomId(int roomId) {
		this.roomId = roomId;
	}

	public String getBody() {
		return body;
	}

	public void setBody(String body) {
		this.body = body;
	}

	public int getId() {
		return Id;
	}

	public void setId(int Id) {
		this.Id = Id;
	}

	public int getIndex() {
		return Index;
	}

	public void setIndex(int Index) {
		this.Index = Index;
	}

	public int getUserIndex() {
		return userIndex;
	}

	public void setUserIndex(int userIndex) {
		this.userIndex = userIndex;
	}

	public int getRoomIndex() {
		return roomIndex;
	}

	public void setRoomIndex(int roomIndex) {
		this.roomIndex = roomIndex;
	}

	public boolean getStarred() {
		return starred;
	}

	public void setStarred(boolean starred) {
		this.starred = starred;
	}

	public String getDate() {
		return dateCreated;
	}

	public void setDate(String date) {
		// pad the date if necessary
		dateCreated = date;
	}

	public Message copy() {
		Message copy = new Message();
		copy.type = type;
		copy.body = body;
		copy.dateCreated = dateCreated;
		copy.Id = Id;
		copy.roomIndex = roomIndex;
		copy.userIndex = userIndex;
		copy.starred = starred;
		return copy;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("Title: ");
		sb.append(body);
		sb.append('\n');
		sb.append("Date: ");
		sb.append(this.getDate());
		sb.append('\n');
		sb.append('\n');
		sb.append("Message: ");
		sb.append(type);
		return sb.toString();
	}

	@Override
	public boolean equals(Object obj) {

		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Message other = (Message) obj;
		return this.getId()==other.getId();
		
	}

	public int compareTo(Message another) {
		if (another == null)
			return 1;
		// sort descending, most recent first
		return another.dateCreated.compareTo(dateCreated);
	}
}